package com.filldream.fastboot.core.event.listener;

import com.filldream.fastboot.base.entity.OssResource;
import com.filldream.fastboot.base.mapper.OssResourceMapper;
import com.filldream.fastboot.core.event.OssEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @author RickSun
 * @Description 监听OSS资源添加
 **/
@Slf4j
@Component
public class OssEventListener implements ApplicationListener<OssEvent> {

	@Resource
	private OssResourceMapper ossResourceMapper;

	@Async
	public void onApplicationEvent(OssEvent ossEvent) {
		OssResource ossResource = (OssResource)ossEvent.getSource();
		if( ossResource != null ){
			try {
				ossResourceMapper.insert(ossResource);
			}catch (Exception e){
				log.info("上传文件同步数据库异常:{}",e.getMessage());
			}

		}
		return;
	}

}